using MediatR;
using Microsoft.AspNetCore.Mvc;
using ProduceBasicData.Api.Application.Command.WarehouseManage;
using ProduceBasicData.Api.DTO.WarehouseDto;
using ProduceBasicData.ErrorCode;
using Swashbuckle.AspNetCore.Annotations;

namespace ProduceBasicData.Api.Controllers.WarehouseManage
{
    /// <summary>
    /// 出库单控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class StockOutOrderController : ControllerBase
    {
        private readonly IMediator _mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public StockOutOrderController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 创建出库单
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreateStockOutOrder(CreateStockOutOrderCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 获取出库单列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<StockOutOrderDto>> GetStockOutOrderList([FromQuery] GetStockOutOrderCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 更新出库单
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateStockOutOrder(UpdateStockOutOrderCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 删除出库单
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteStockOutOrder(DeleteStockOutOrderCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 出库单批量删除
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteRangeStockOutOrder(DeleteRangeStockOutOrderCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 执行出库操作
        /// </summary>
        /// <param name="command">出库命令</param>
        /// <returns>操作结果</returns>
        [HttpPut]
        public async Task<ApiResult<int>> OutWarehouse([FromBody] OutWarehouseCommand command)
        {
            return await _mediator.Send(command);
        }
    }
}